<!DOCTYPE html>
<html>
<head body_color=FahJzm >
    <meta charset="utf-8">
    <title>{$webname}-供应商系统</title>
    <style>
        #myiframe{
            position: absolute;
            top: 0;
            bottom: 0;
            height:100%;
            width: 100%;
            border: none;
        }
    </style>
</head>
<body>
{request 'pc/pub/header'}
<!-- 公用顶部 -->
{request 'pc/pub/left_menu'}
<!-- 公共侧边栏 -->
<div class="supplier-main-container">
    <div class="supplier-main-wrap">
        <iframe class="iframe-body" src="{$index_link}" id="myiframe" scrolling="yes" frameborder="0"></iframe>
    </div>
</div>

<div class="global-layer-container order_notice_window" style="display: none">
    <div class="global-layer-wrap">
        <div class="global-layer-title">
            订单提醒
            <a href="javascript:;" class="audio-btn" title="订单提示"></a>
            <a href="javascript:;" class="clear-btn clear_all_notice" title="清除"></a>
            <a href="javascript:;" class="zhe-btn" title="关闭"></a>
        </div>
        <div class="global-layer-content" style="display: none" >
            <ul class="global-layer-list order_notice_window_ul" style="display: none">

            </ul>
            <div class="global-layer-tips no_order" style="display: none">暂无订单提醒~</div>
        </div>
    </div>
</div>

<!--    controls-->
<audio id="myAudio" preload="auto" muted >
    <source src="/res/mp3/order.mp3" type="audio/mpeg">
</audio>
<div class="global-layer-muted clearfix">
    <a href="javascript:;" class="player-btn open_audio"><i class="icon"></i>打开声音</a>
    <a href="javascript:;" class="player-btn muted-btn"><i class="icon"></i>静音提示</a>
</div>

<script>
    var SITEURL = "{$cmsurl}";
    $(function (){
        order_notice_window()
        //折叠展开
        $(".zhe-btn").on("click",function(){
            if($(".global-layer-content").hasClass("on")){
                $(".global-layer-content").removeClass("on");
                $(this).removeClass("up");
                $(".clear-btn").show();
                $(this).attr("title","关闭");
            }else{
                $(".global-layer-content").addClass("on");
                $(this).addClass("up");
                $(".clear-btn").hide();
                $(this).attr("title","展开");

            }
        });

        //清除所有
        $('.clear_all_notice').click(function () {
            $.ajax({
                type:'post',
                url:SITEURL+'/pc/index/clear_order_notice',
                data:{},
                dataType:'json',
                success:function(resp){
                    if(resp.status){
                        $('.no_order').show()
                        $('.order_notice_window_ul').html('')
                        $('.order_notice_window_ul').hide()
                    }
                }
            })
        })


        // 播放订单提示音量
        $(".audio-btn").on("click",function(){
            var player = $("#myAudio")[0];
            var muted = player.muted;
            if(muted){
                player.muted = false;
                // player.play();
                $(this).addClass('on')
            }else{
                player.muted = true;
                player.load();
                $(this).removeClass('on')
            }
        });

        //打开
        $('.open_audio').click(function () {
            var player = $("#myAudio")[0];
            var muted = player.muted;
            player.muted = false;
            // player.play();
            $('.audio-btn').addClass('on')
            $('.global-layer-muted').hide()
        })

        // 静音
        $(".muted-btn").on("click",function(){
            var player = $("#myAudio")[0];
            var muted = player.muted;
            player.muted = true;
            player.load();
            $('.audio-btn').removeClass('on')
            $('.global-layer-muted').hide()
        });

    })

    function order_notice_window(){
        var i=0
        timerId = setInterval(function(){
            $.ajax({
                type:'post',
                url:SITEURL+'/pc/index/check_order_window',
                data:{},
                dataType:'json',
                success:function(resp){
                    if(resp.status){
                        console.log('有订单')
                        $('.order_notice_window').show()
                        let html = ''
                        let sattus_name=''
                        let url=''

                        for (let i=0;i<resp.data.length;i++){

                            if(resp.data[i].status==0){
                                status_name='待确认'
                            }else if (resp.data[i].status==1){
                                status_name='待付款'
                            }else if (resp.data[i].status==2){
                                status_name='待消费'
                            }else if (resp.data[i].status==3){
                                status_name='已关闭'
                            }else if (resp.data[i].status==4){
                                status_name='已退款'
                            }else if (resp.data[i].status==5){
                                status_name='已完成'
                            }else if (resp.data[i].status==6){
                                status_name='待审核'
                            }

                            if(resp.data[i].typeid==1){
                                url='/plugins/supplier_line/order/show?id='+resp.data[i].id
                            }else if(resp.data[i].typeid==2){
                                url='/plugins/supplier_hotel/order/show?id='+resp.data[i].id
                            }else if(resp.data[i].typeid==5){
                                url='/plugins/supplier_hotel/order/show?id='+resp.data[i].id
                            }else if(resp.data[i].typeid==13){
                                url='/plugins/supplier_tuan/order/show?id='+resp.data[i].id
                            }else if(resp.data[i].typeid==114){
                                url='/plugins/supplier_outdoor/order/show?id='+resp.data[i].id
                            }else if(resp.data[i].typeid==118){
                                url='/plugins/supplier_techan/order/show?id='+resp.data[i].id
                            }else if(resp.data[i].typeid==121){
                                url='/plugins/supplier_food/order/show?id='+resp.data[i].id
                            }else{
                                url='/plugins/supplier_tongyong/order/show?id='+resp.data[i].id
                            }

                            html+='<li class="return order_notice_window_li" onclick="goto('+"'"+url+"'"+')">'+
                                '<a href="javascript:;">'+
                                '<div class="order-info-top clearfix">'+
                                '<div class="order-sn fl">订单号：'+resp.data[i].ordersn+'</div>'+
                                '<div class="order-status fr">'+status_name+'</div>'+
                                '</div>'+
                                '<div class="order-info-bottom">'+
                                '<div class="order-tit">'+resp.data[i].productname+'('+resp.data[i].suit_name+')'+'</div>'+
                                '<div class="order-data clearfix">'+
                                '<div class="name fl">'+resp.data[i].linkman+'</div>'+
                                '<div class="phone fl ml10">'+resp.data[i].linktel+'</div>'+
                                '<div class="time fr">'+resp.data[i].addtime+'</div>'+
                                '</div>'+
                                '</div>'+
                                '</a>'+
                                '</li>'
                        }
                        $('.global-layer-content').show()
                        $('.no_order').hide()
                        $('.order_notice_window_ul').show()
                        $('.order_notice_window_ul').html(html)

                        play_audio()

                    }else{
                        console.log('没有订单')
                        // $('.global-layer-content').show()
                        // $('.order_notice_window_ul').hide()
                        // $('.order_notice_window_ul').html('')
                        // $('.no_order').show()
                        $('.order_notice_window').hide()
                    }
                }
            })
            if(i<0){
                clearInterval(timerId);
            }
        },3000)
    }

    function goto(url){
        $('.iframe-body').attr('src',url);
    }

    function play_audio(){
        $.ajax({
            type:'post',
            url:SITEURL+'/pc/index/check_order_mp3',
            data:{},
            dataType:'json',
            success:function(data){
                if(data.status){
                    console.log('需要自动播放音频')
                    $('#myAudio')[0].play();
                }
            }
        })
    }
</script>
<!-- 内容 -->
</body>
</html>
